<?php
function application_form($first_name='',$last_name='',$email='', $phone_number='', $program_title='',$location='',$source='',$agent_number='',$more_information='',$errors=''){
	global $post;
	if ( !is_wp_error($errors) ) $errors = new WP_Error();		
	$content = $post->post_content;
	$content = apply_filters('the_content', $content);	
?>
				<div class ="page_content">
					<?php echo $content; ?>
				</div>
				<div class ="clr"></div>
				
				<div class = "standard_form_zone">
					<form id="appication_form" class = "standard_form" method="post" action="<?php the_permalink($post->ID);?>">
						<input type="hidden" name="stage" value="validate_form"/>
						<div class = "block_header"><p>Student Information</p></div>
							<?php if ( $errmsg = $errors->get_error_message('first_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>First Name</label><input name="first_name" type="text" id="first_name" value="<?php echo $first_name;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('last_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Last Name</label><input name="last_name" type="text" id="last_name" value="<?php echo $last_name;?>" /><span class = "mandatory_item">*</span>					
						<div class = "block_header"><p>Program of Interest</p></div>
							<?php if ( $errmsg = $errors->get_error_message('program_title') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Please select an area</label><?php get_program_title($program_title);?><span class = "mandatory_item">*</span>
						<div class = "block_header"><p>Contact Informaion</p></div>
							<?php if ( $errmsg = $errors->get_error_message('email') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>E-mail Address</label><input name="email" type="text" id="email" value="<?php echo $email;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('phone_number') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Phone Number</label><input name="phone_number" type="text" id="phone_number" value="<?php echo $phone_number;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('location') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Location</label><?php show_locaion_select($location);?>	<span class = "mandatory_item">*</span>			
							<label>How did you hear about us</label><?php show_source_select($source);?>
							<label>Agent Number</label><input name="agent_number" type="text" id="agent_number" value="<?php echo $agent_number;?>" />
						<div class = "block_header"><p>Anything else you would like to tell us</p></div>
							<textarea name="more_information" id="more_information" class="more_information"><?php echo $more_information;?></textarea>

						<input type="submit" class="application_submit" name="application_submit" id="application_submit" value="Click here to Submit your information" />
						<?php wp_nonce_field( 'application_apply_now','apply_now' ); ?>						
					</form>
				</div>
<?php 	
}

function validate_application_form(){
	$first_name = $_POST['first_name'];	
	$last_name = $_POST[ 'last_name' ];
	$email = $_POST['email'];	
	$phone_number = $_POST[ 'phone_number' ];	
	$program_title = $_POST['program_title'];
	$location = $_POST['location'];
	$source = $_POST['source'];
	$agent_number = $_POST['agent_number'];
	$more_information = $_POST['more_information'];
	$old_email = $email;
	$errors = new WP_Error();
	$email_after_sanitize = sanitize_email($email);

	if (!$first_name || !$last_name || !$email || $old_email != $email_after_sanitize || !$phone_number || !$program_title || !$location){		
		if(!$first_name) $errors->add( 'first_name','Please fill first name ' );
		if(!$last_name) $errors->add( 'last_name','Please fill last name ' );
		if(!$email) $errors->add( 'email','Please fill your E-mail address' );
		else if ($old_email != $email_after_sanitize) $errors->add( 'email','Please double check your email' );
		if(!$phone_number) $errors->add( 'phone_number','Please fill phone number ' );
		if(!$program_title) $errors->add( 'program_title','Please choose a program title ' );
		if(!$location) $errors->add( 'location','Please choose your location ' );
		
		application_form($first_name,$last_name,$email, $phone_number, $program_title,$location,$source,$agent_number,$more_information,$errors);
	}
	else{
		check_admin_referer( 'application_apply_now' ,'apply_now');
		$post_title = $first_name . ' ' . $last_name;
		$post_content = 'First Name:  ' . $first_name. '<br />';
		$post_content .= 'Last Name:  ' . $last_name. '<br />';
		$post_content .= 'E-mail:  ' . $email. '<br />';
		$post_content .= 'Phone Number:  ' . $phone_number. '<br />';
		$post_content .= 'Program of Interest:  ' . $program_title. '<br />';
		$post_content .= 'Location:  ' . $location. '<br />';
		$post_content .= 'How to hear about us:  ' . $source. '<br />';
		$post_content .= 'Something else tell us:  ' . $more_information. '<br />';
		$post = array(
					'post_author' => 1,
					'post_type' => 'application',
					'post_status' => 'publish',
					'post_title' => $post_title,
					'post_content' => $post_content,
			);
		
		if ($post_id = wp_insert_post( $post )){
			$mailto= array('gerald@saicanada.com','cheryl@saicanada.com');
//			$mailto= array('jim.lijx@gmail.com');  
			$subject = 'Application from '. $post_title;
			$message = "
			First Name:		$first_name
			Last Name:		$last_name
			E-mail:		$email
			Phone Number:		$phone_number
			Program of Interest:		$program_title
			Location:		$location
			How to hear about us:		$source
			Agent Number:		$agent_number
			Something else tell us:		$more_information";
			wp_mail($mailto, $subject, $message);
			echo '<div class = "sucess_inforation">Thanks, you have successfully submitted your information, we will contact you later</div>';
		}
	}
}

function feedback_form($first_name='',$last_name='',$email='',  $issue_category='',$source='',$feedback_content='',$errors=''){
	global $post;
	if ( !is_wp_error($errors) ) $errors = new WP_Error();		
	$content = $post->post_content;
	$content = apply_filters('the_content', $content);	
?>
				<div class ="page_content">
					<?php echo $content; ?>
				</div>
				<div class ="clr"></div>
				
				<div class = "standard_form_zone">
					<form id="feedback_form" class = "standard_form" method="post" action="<?php the_permalink($post->ID);?>">
						<input type="hidden" name="stage" value="validate_form"/>
						<div class = "block_header"><p>Personal Information</p></div>
							<?php if ( $errmsg = $errors->get_error_message('first_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>First Name</label><input name="first_name" type="text" id="first_name" value="<?php echo $first_name;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('last_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Last Name</label><input name="last_name" type="text" id="last_name" value="<?php echo $last_name;?>" /><span class = "mandatory_item">*</span>					
						<div class = "block_header"><p>What is your issue about?</p></div>
							<?php if ( $errmsg = $errors->get_error_message('issue_category') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Please select your issue</label><?php show_issue_category($issue_category);?><span class = "mandatory_item">*</span>
						<div class = "block_header"><p>Contact Informaion</p></div>
							<?php if ( $errmsg = $errors->get_error_message('email') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>E-mail Address</label><input name="email" type="text" id="email" value="<?php echo $email;?>" /><span class = "mandatory_item">*</span>
							<label>How did you hear about us</label><?php show_source_select($source);?>
						<div class = "block_header"><p>Your Issue</p></div>
							<textarea name="feedback_content" id="feedback_content" class="feedback_content"><?php echo $feedback_content;?></textarea>

						<input type="submit" class="feedback_submit" name="feedback_submit" id="feedback_submit" value="Click here to Submit your information" />
						<?php wp_nonce_field( 'feedback_form','feedback' ); ?>						
					</form>
				</div>
<?php 	
}

function validate_feedback_form(){
	$first_name = $_POST['first_name'];	
	$last_name = $_POST[ 'last_name' ];
	$email = $_POST['email'];			
	$issue_category = $_POST['issue_category'];
	$source = $_POST['source'];
	$feedback_content = $_POST['feedback_content'];
	$old_email = $email;
	$errors = new WP_Error();
	$email_after_sanitize = sanitize_email($email);

	if (!$first_name || !$last_name || !$email || $old_email != $email_after_sanitize ||!$issue_category){		
		if(!$first_name) $errors->add( 'first_name','Please fill first name ' );
		if(!$last_name) $errors->add( 'last_name','Please fill last name ' );
		if(!$email) $errors->add( 'email','Please fill your E-mail address' );
		else if ($old_email != $email_after_sanitize) $errors->add( 'email','Please double check your email' );	
		if(!$issue_category) $errors->add( 'issue_category','Please choose your issue ' );
		feedback_form($first_name,$last_name,$email, $issue_category,$source,$feedback_content,$errors);
	}
	else{
		check_admin_referer( 'feedback_form','feedback');
		$post_title = $first_name . ' ' . $last_name;
		$post_content = 'First Name:  ' . $first_name. '<br />';
		$post_content .= 'Last Name:  ' . $last_name. '<br />';
		$post_content .= 'E-mail:  ' . $email. '<br />';
		$post_content .= 'Issue Category:  ' . $issue_category. '<br />';
		$post_content .= 'How to hear about us:  ' . $source. '<br />';
		$post_content .= 'Question/Comment:  ' . $feedback_content. '<br />';
		$post = array(
					'post_author' => 1,
					'post_type' => 'feedback_question',
					'post_status' => 'publish',
					'post_title' => $post_title,
					'post_content' => $post_content,
			);
		
		if ($post_id = wp_insert_post( $post )){
			$mailto= array('gerald@saicanada.com','cheryl@saicanada.com'); 
			$subject = 'Feedback from '. $post_title;
			$message = "
			First Name:		$first_name
			Last Name:		$last_name
			E-mail:		$email
			Issue Category:		$issue_category
			How to hear about us:		$source			
			Question/Comment::		$feedback_content";
			
			wp_mail($mailto, $subject, $message);
			echo '<div class = "sucess_inforation">Thanks, you have successfully submitted your information, we will contact you later</div>';
		}
	}
}

function allowance_form($first_name='',$last_name='',$email='', $phone_number='', $allowance_period = '', $allowance_amount = '', $more_information='',$errors=''){
	global $post;
	if ( !is_wp_error($errors) ) $errors = new WP_Error();		
?>				
				<div class = "standard_form_zone">
					<form id="appication_form" class = "standard_form" method="post" action="<?php echo SITEURL . '/services/student-allowance-service/';?>">
						<input type="hidden" name="stage" value="validate_form"/>
						<div class = "block_header"><p>Student Information</p></div>
							<?php if ( $errmsg = $errors->get_error_message('first_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>First Name</label><input name="first_name" type="text" id="first_name" value="<?php echo $first_name;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('last_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Last Name</label><input name="last_name" type="text" id="last_name" value="<?php echo $last_name;?>" /><span class = "mandatory_item">*</span>					
						<div class = "block_header"><p>Allowance Option</p></div>
							<?php if ( $errmsg = $errors->get_error_message('allowance_period') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Please select an option</label>
								<select id = "allowance_period" name = "allowance_period">
									<option value = "">Select option</option>
									<option value = "Every day">Every day</option>
									<option value = "Every week">Every week</option>
									<option value = "Every two weeks">Every two weeks</option>
									<option value = "Every month">Every month</option>
									<option value = "None of the above">None of the above</option>
								</select>
							<span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('allowance_amount') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Please enter amount(in Canadian Dollars)</label><input name="allowance_amount" type="text" id="allowance_amount" value="<?php echo $allowance_amount;?>" /><span class = "mandatory_item">*</span>					
							
						<div class = "block_header"><p>Parent/Guardian Contact Informaion</p></div>
							<?php if ( $errmsg = $errors->get_error_message('email') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>E-mail Address</label><input name="email" type="text" id="email" value="<?php echo $email;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('phone_number') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Phone Number</label><input name="phone_number" type="text" id="phone_number" value="<?php echo $phone_number;?>" /><span class = "mandatory_item">*</span>
						<div class = "block_header"><p>Anything else you would like to tell us</p></div>
							<textarea name="more_information" id="more_information" class="more_information"><?php echo $more_information;?></textarea>

						<input type="submit" class="application_submit" name="application_submit" id="application_submit" value="Click here to Submit your information" />
						<?php wp_nonce_field( 'student_allowance_service','allowance_service' ); ?>						
					</form>
				</div>
<?php 	
}

function validate_allowance_form(){
	$first_name = $_POST['first_name'];	
	$last_name = $_POST[ 'last_name' ];
	$email = $_POST['email'];	
	$phone_number = $_POST[ 'phone_number' ];
	$allowance_period = $_POST[ 'allowance_period' ];
	$allowance_amount = $_POST[ 'allowance_amount' ];	
	$more_information = $_POST['more_information'];
	$old_email = $email;
	$errors = new WP_Error();
	$email_after_sanitize = sanitize_email($email);

	if (!$first_name || !$last_name || !$email || $old_email != $email_after_sanitize || !$phone_number || !$allowance_period || !$allowance_amount){		
		if(!$first_name) $errors->add( 'first_name','Please fill first name ' );
		if(!$last_name) $errors->add( 'last_name','Please fill last name ' );
		if(!$email) $errors->add( 'email','Please fill your E-mail address' );
		else if ($old_email != $email_after_sanitize) $errors->add( 'email','Please double check your email' );
		if(!$phone_number) $errors->add( 'phone_number','Please fill phone number ' );
		if(!$allowance_period) $errors->add( 'allowance_period','Please choose a allowance option ' );
		if(!$allowance_amount) $errors->add( 'allowance_amount','Please fill allowance amount in Canadian dollars ' );
		
		allowance_form($first_name,$last_name,$email, $phone_number,$allowance_period,$allowance_amount, $more_information,$errors);
	}
	else{
		check_admin_referer( 'student_allowance_service' ,'allowance_service');
		$post_title = $first_name . ' ' . $last_name;
		$post_content = 'First Name:  ' . $first_name. '<br />';
		$post_content .= 'Last Name:  ' . $last_name. '<br />';
		$post_content .= 'E-mail:  ' . $email. '<br />';
		$post_content .= 'Phone Number:  ' . $phone_number. '<br />';
		$post_content .= 'Allowance Option:  ' . $allowance_period. '<br />';
		$post_content .= 'Allowance Amount:  ' . $allowance_amount. '<br />';
		
		$post_content .= 'Something else tell us:  ' . $more_information. '<br />';
		$post = array(
					'post_author' => 1,
					'post_type' => 'allowance',
					'post_status' => 'publish',
					'post_title' => $post_title,
					'post_content' => $post_content,
			);
		
		if ($post_id = wp_insert_post( $post )){
			$mailto= array('gerald@saicanada.com','cheryl@saicanada.com');
//			$mailto= array('jim.lijx@gmail.com');  
			$subject = 'Allowance from '. $post_title;
			$message = "
			First Name:		$first_name
			Last Name:		$last_name
			E-mail:		$email
			Phone Number:		$phone_number
			Allowance Option:		$allowance_period
			Allowance Amount:		$allowance_amount			
			Something else tell us:		$more_information";
			wp_mail($mailto, $subject, $message);
			echo '<div class = "sucess_inforation">Thanks, you have successfully submitted your information, we will contact you later</div>';
		}
	}
}



function question_form($first_name='',$last_name='',$email='', $phone_number='', $program_title='',$location='',$source='',$more_information='',$errors=''){
	global $post;
	if ( !is_wp_error($errors) ) $errors = new WP_Error();		
	$content = $post->post_content;
	$content = apply_filters('the_content', $content);	
?>
				<div class ="page_content">
					<?php echo $content; ?>
				</div>
				<div class ="clr"></div>
				
				<div class = "standard_form_zone">
					<form id="appication_form" class = "standard_form" method="post" action="<?php the_permalink($post->ID);?>">
						<input type="hidden" name="stage" value="validate_form"/>
						<div class = "block_header"><p>Please give us some information about yourself and one of our Education Consultants will personally contact you and answer any questions</p></div>
							<?php if ( $errmsg = $errors->get_error_message('first_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>First Name</label><input name="first_name" type="text" id="first_name" value="<?php echo $first_name;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('last_name') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Last Name</label><input name="last_name" type="text" id="last_name" value="<?php echo $last_name;?>" /><span class = "mandatory_item">*</span>					
						<div class = "block_header"><p>Please select your Program of Interest</p></div>
							<?php if ( $errmsg = $errors->get_error_message('program_title') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Please select a interest progam</label><?php get_program_title($program_title);?><span class = "mandatory_item">*</span>
						<div class = "block_header"><p>Contact Informaion</p></div>
							<?php if ( $errmsg = $errors->get_error_message('email') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>E-mail Address</label><input name="email" type="text" id="email" value="<?php echo $email;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('phone_number') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Phone Number</label><input name="phone_number" type="text" id="phone_number" value="<?php echo $phone_number;?>" /><span class = "mandatory_item">*</span>
							<?php if ( $errmsg = $errors->get_error_message('location') ) { ?>
									<p class="error"><?php echo $errmsg ?></p>
							<?php } ?>
							<label>Where are you located</label><?php show_locaion_select($location);?>	<span class = "mandatory_item">*</span>			
							<label>How did you hear about us</label><?php show_source_select($source);?>
						<div class = "block_header"><p>Anything else you would like to tell us</p></div>
							<textarea name="more_information" id="more_information" class="more_information"><?php echo $more_information;?></textarea>

						<input type="submit" class="application_submit" name="application_submit" id="application_submit" value="Click here to Submit your information" />
						<?php wp_nonce_field( 'application_apply_now','apply_now' ); ?>						
					</form>
				</div>
<?php 	
}

function validate_question_form(){
	$first_name = $_POST['first_name'];	
	$last_name = $_POST[ 'last_name' ];
	$email = $_POST['email'];	
	$phone_number = $_POST[ 'phone_number' ];	
	$program_title = $_POST['program_title'];
	$location = $_POST['location'];
	$source = $_POST['source'];
	$more_information = $_POST['more_information'];
	$old_email = $email;
	$errors = new WP_Error();
	$email_after_sanitize = sanitize_email($email);

	if (!$first_name || !$last_name || !$email || $old_email != $email_after_sanitize || !$phone_number || !$program_title || !$location || !$source){		
		if(!$first_name) $errors->add( 'first_name','Please fill first name ' );
		if(!$last_name) $errors->add( 'last_name','Please fill last name ' );
		if(!$email) $errors->add( 'email','Please fill your E-mail address' );
		else if ($old_email != $email_after_sanitize) $errors->add( 'email','Please double check your email' );
		if(!$phone_number) $errors->add( 'phone_number','Please fill phone number ' );
		if(!$program_title) $errors->add( 'program_title','Please choose a program title ' );
		if(!$location) $errors->add( 'location','Please choose your location ' );
		
		application_form($first_name,$last_name,$email, $phone_number, $program_title,$location,$source,$more_information,$errors);
	}
	else{
		check_admin_referer( 'application_apply_now' ,'apply_now');
		$post_title = $first_name . ' ' . $last_name;
		$post_content = 'First Name:  ' . $first_name. '<br />';
		$post_content .= 'Last Name:  ' . $last_name. '<br />';
		$post_content .= 'E-mail:  ' . $email. '<br />';
		$post_content .= 'Phone Number:  ' . $phone_number. '<br />';
		$post_content .= 'Program of Interest:  ' . $program_title. '<br />';
		$post_content .= 'Location:  ' . $location. '<br />';
		$post_content .= 'How to hear about us:  ' . $source. '<br />';
		$post_content .= 'Something else tell us:  ' . $more_information. '<br />';
		$post = array(
					'post_author' => 1,
					'post_type' => 'application',
					'post_status' => 'publish',
					'post_title' => $post_title,
					'post_content' => $post_content,
			);
		
		if ($post_id = wp_insert_post( $post )){
			$mailto= array('gerald@saicanada.com','cheryl@saicanada.com'); 
			$subject = 'Application from '. $post_title;
			wp_mail($mailto, $subject, $post_content);
			echo '<div class = "sucess_inforation">Thanks, you have successfully submitted your information, we will contact you later</div>';
		}
	}
}


function get_program_title($program_title_selected = ''){
	$output = '';
	$program_page_id = 175;
	$args = array(	
  				'post_type' 	=> 'page',
				'post_status'	=> 'publish',
				'post_parent'	=>	$program_page_id,
				'orderby' 		=> 'menu_order',
				'order'			=> 'ASC'
			);
	$the_query = new WP_Query( $args );
						
	if ($the_query->have_posts()) {
			$output .= '<select id = "program_title" name = "program_title">';
			$output .= 	'<option value = "">Select your area of interest</option>';
			while ($the_query->have_posts()) {
					$the_query->the_post();
					$post_id =  get_the_ID();
					$title = get_the_title($post_id);
					$seleted = ($program_title_selected && $program_title_selected == $title) ? 'selected="selected"':'';					
					$output .= 	'<option value = "' . $title. '" ' . $seleted .'>'. $title . '</option>';
			}
			$output .= 	'<option value = "other">Other</option>';
			$output .= 	'</select>';			
	}				
	echo $output;
}

function show_locaion_select($location_selected = ''){
	$output = '';
	$locations = array(
						'Canada',
						'China',
						'France',
						'India',
						'Korea',
						'Other'
				);
	$output .= '<select id = "location" name = "location">';
	$output .= 	'<option value = "">Select your country</option>';
	foreach ($locations as $location){
					$seleted = ($location_selected && $location_selected == $location) ? 'selected="selected"':'';					
					$output .= 	'<option value = "' . $location. '" ' . $seleted .'>'. $location . '</option>';
	}
	$output .= 	'</select>';
	echo $output;
}

function show_issue_category($issue_category = ''){
	$output = '';
	$issue_category_array = array(
						'School',
						'Residence',
						'Service',
						'Website',
				);
	$output .= '<select id = "issue_category" name = "issue_category">';
	$output .= 	'<option value = "">Select your issue category</option>';
	foreach ($issue_category_array as $issue){
					$seleted = ($issue_category && $issue_category == $issue) ? 'selected="selected"':'';					
					$output .= 	'<option value = "' . $issue. '" ' . $seleted .'>'. $issue . '</option>';
	}
	$output .= 	'</select>';
	echo $output;
}

function show_source_select($source_selected=''){
	$output = '';
	$sources = array(
						'News or Print',
						'TV',
						'Google',
						'Facebook',
						'Other Website',
						'Sign',
						'Brochure',
						'Flyer',
						'Event',
						'Outreach',
						'Telesales',
						'Referral',
						'Other'
				);
	$output .= '<select id = "source" name = "source">';
	$output .= 	'<option value = "">How did you know about us</option>';
	foreach ($sources as $source){
					$seleted = ($source_selected && $source_selected == $source) ? 'selected="selected"':'';					
					$output .= 	'<option value = "' . $source. '" ' . $seleted .'>'. $source . '</option>';
	}
	$output .= 	'</select>';
	echo $output;
	
}
?>